class Solution
{
public:
    string longestPalindrome(string s)
    {
        int size = s.size(), begin = 0, len = 0;
        for (int cur = 0; cur < size; cur++)
        {
            int left = cur - 1, right = cur + 1;
            for (; left >= 0 && right < size; right++, left--)
            {
                if (s[left] != s[right]) break;
            }
            if (right - left - 1 > len)
            {
                begin = left + 1;
                len = right - left - 1;
            }
            left = cur, right = cur + 1;
            for (; left >= 0 && right < size; right++, left--)
            {
                if (s[left] != s[right]) break;
            }
            if (right - left - 1 > len)
            {
                begin = left + 1;
                len = right - left - 1;
            }
        }
        return s.substr(begin, len);
    }
};
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        string s;
        int sign = 1, size = strs.size(), countsize = strs[0].size();
        for (int cur = 0; cur < countsize; cur++)
        {
            char ch = strs[0][cur];
            for (int i = 1; i < size; i++)
            {
                if (strs[i][cur] != ch)
                {
                    sign = 0;
                    break;
                }
            }
            if (sign) s += ch;
            else break;
        }
        return s;
    }
};
